import React, {Component} from 'react';
import {
    Button,
    Platform,
    StyleSheet,
    Text,
    TextInput,
    TouchableOpacity,
    View
} from 'react-native';
import ToastComponent from "../common/Toast";
import Orientation from "react-native-orientation";
import Utils from '../common/Utils';
import Storage from '../common/Storage';

export default class Home extends React.Component {
    state = {
        text: '1111',
    };

    componentWillMount() {
        Orientation.lockToPortrait();
    }

    static navigationOptions = {
        // headerLeft: (
        //     <Button
        //         title="back"
        //         color="#ffffff00"
        //     />
        // ),
        // headerRight: (
        //     <Button
        //         onPress={() => alert('This is a button!')}
        //         title="Itiels"
        //         color="#ffffff00"
        //     />
        // ),
    };


    render() {
        let keys = 'sssdff';
        return (
            <View style={{
                flex: 1,
                flexDirection: 'column',
                justifyContent: 'center',
                backgroundColor: '#F5FCFF',
            }}>
                <TextInput ref={input => this.input = input} defaultValue={'123123123'}
                onChangeText={(tt)=>this.state.text = tt}
                />
                <Button title={'保存数据'} onPress={() => {
                    alert(this.state.text);
                    Storage.save(keys, this.state.text);
                    this.setState({text: this.state.text});
                }}/>

                <Button title={'读取数据'} onPress={() => {
                    // Storage.get(key,(value)=>(
                    //     this.setState({text: value})
                    // ));
                    // Utils.getStorage(keys, (value) => {
                    //     this.setState({text: value+"aaa"});
                    // });
                }}/>
                <TouchableOpacity onPress={() => {
                    // this.props.navigation.navigate('Welcome');
                    ToastComponent.show('123123');
                }}>
                    <Text style={{fontSize: 20, backgroundColor: 'orange'}}>
                        {this.state.text}
                    </Text>
                </TouchableOpacity>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
    },
    textInput: {
        width: 200,
        color: '#333333',
        height: 60,
        marginTop: 50,
    },
});




